<template>
  <div class="container">
    <p class="info">
      搜索“{{ content }}”，找到<span>&nbsp;{{ num }}&nbsp;</span>{{ typename }}
    </p>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      // 搜索内容
      content: "",
      // 数据总量
      num: "",
      // 搜索的类型
      type: "",
      typename: "",
    };
  },
  created() {
    this.content = this.$route.params.value;
    this.type = this.$router.history.current.name;
    switch (this.$router.history.current.name) {
      case "1":
        this.searchA();
        break;
      case "100":
        this.searchB();
        break;
      case "10":
        this.searchC();
        break;
      case "1014":
        this.searchD();
        break;
      case "1006":
        this.searchE();
        break;
      case "1000":
        this.searchF();
        break;
      case "1009":
        this.searchG();
        break;
      case "1002":
        this.searchH();
        break;
    }
  },
  methods: {
    searchA() {
      this.typename = "首单曲";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.songCount < 30) {
            this.num = res.data.result.songCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchB() {
      this.typename = "个歌手";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.artistCount < 30) {
            this.num = res.data.result.artistCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchC() {
      this.typename = "张专辑";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.albumCount < 30) {
            this.num = res.data.result.albumCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchD() {
      this.typename = "个视频";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.videoCount < 30) {
            this.num = res.data.result.videoCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchE() {
      this.typename = "个歌词";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.songCount < 30) {
            this.num = res.data.result.songCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchF() {
      this.typename = "个歌单";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.playlistCount < 30) {
            this.num = res.data.result.playlistCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchG() {
      this.typename = "个节目";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.djRadiosCount < 30) {
            this.num = res.data.result.djRadiosCount;
          } else {
            this.num = 30;
          }
        });
    },
    searchH() {
      this.typename = "个用户";
      axios
        .get(
          `http://127.0.0.1:3000/cloudsearch?keywords=${this.content}&type=${this.type}`
        )
        .then((res) => {
          if (res.data.result.userprofileCount < 30) {
            this.num = res.data.result.userprofileCount;
          } else {
            this.num = 30;
          }
        });
    },
  },
};
</script>
<style scoped>
.container .info {
  font-size: 12px;
  color: #999;
}
.container .info span {
  color: #c20c0c;
}
</style>